var app = new Vue({
    el: '#myapp',
    data: {
        searchName: '',
        searchResult: [],
        page: 0,
        loading: false,
        lastPage: false,
        maxheight: false
    },
    created: function created() {
        this.getSearchResult();
        var vm = this;
        window.addEventListener('scroll', function (e) {
            var ph = window.screen.height;
            var dh = window.scrollY;
            var re = vm.$refs.result.scrollHeight;
            //   console.log(ph)
            if (dh + ph >= re && !vm.loading && !vm.lastPage) {
                vm.page += 1;
                vm.getSearchResult();
            }
        });
    },
    mounted: function mounted() {
        // var result = this.$refs.result
        // var re = document.getElementById('result');
        // console.log(result);

        // re.addEventListener("scroll",function(){
        //     console.log(1);
        // });


    },

    methods: {
        onScroll: function onScroll(e) {
            console.log(e);
        },
        getCommunity: function getCommunity(index) {
            localStorage.currentCommunity = JSON.stringify(this.searchResult[index]);
            window.location.href = '/login.html';
        },
        search: function search() {
            this.page = 0;
            this.getSearchResult();
        },
        getSearchResult: function getSearchResult() {
            var vm = this;
            vm.loading = true;
            request.get('/community', {
                params: {
                    page: this.page,
                    w: vm.searchName
                }
            }).then(function (body) {

                vm.loading = false;
                if (vm.page === 0) {
                    vm.searchResult = [];
                }
                vm.searchResult = vm.searchResult.concat(body.data.content);
                vm.lastPage = body.data.last;
            });
            // axios.get("/mock/community",{
            //     params:{
            //         page: this.page,
            //         w:vm.searchName
            //     }
            // }).then(body=>{
            //     vm.searchResult = body.data.data.content
            // })
        },
        getNull: function getNull() {
            this.searchName = '';
        }
    }
});